package base

import "lesson01/rtda"

// Instruction 指令集
type Instruction interface {
	FetchOperands(reader *BytecodeReader) //从字节码中提前操作数
	Execute(frame *rtda.Frame)            //执行逻辑
}

// NoOperandsInstruction 无操作数
type NoOperandsInstruction struct {
}

func (e *NoOperandsInstruction) FetchOperands(reader *BytecodeReader) {
	// 什么都不做
}

// BranchInstruction 跳转指令
type BranchInstruction struct {
	Offset int
}

func (e *BranchInstruction) FetchOperands(reader *BytecodeReader) {
	e.Offset = int(reader.ReadInt16())
}

type Index8Instruction struct {
	Index uint
}

func (e *Index8Instruction) FetchOperands(reader *BytecodeReader) {
	e.Index = uint(reader.ReadUint8())
}

type Index16Instruction struct {
	Index uint
}

func (e *Index16Instruction) FetchOperands(reader *BytecodeReader) {
	e.Index = uint(reader.ReadUint16())
}
